import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'node:path';

export default defineConfig(({ mode }) => {
  return {
    plugins: [vue()],
    resolve: {
      alias: {
        '@': path.resolve(new URL('.', import.meta.url).pathname, 'src')
      }
    },
    server: {
      port: 5173,
      open: true,
      proxy: {
        '/api': {
          target: process.env.BACKEND_URL || 'http://localhost:9500',
          changeOrigin: true
          //rewrite: p => p.replace(/^\/api/, '')
        }
      }
    },
    build: {
      sourcemap: mode !== 'production',
      rollupOptions: {
        output: {
          manualChunks: {
            'vendor-vue': ['vue','vue-router','pinia'],
            'vendor-pdf': ['jspdf','html2canvas'],
          }
        }
      },
      chunkSizeWarningLimit: 900
    }
  };
});
